﻿//-----------------------------------------------------------------------
// <copyright file="ContactManagerMapperProfile.cs" company="OverrideThis">
//     Copyright (c) 2010 OverrideThis.com
// </copyright>
//-----------------------------------------------------------------------
namespace OverrideThis.ContactManager.WebSite.Infrastructure.Mapper
{
    using System.Collections.Generic;
    using AutoMapper;
    using OverrideThis.ContactManager.Domain;
    using OverrideThis.ContactManager.WebSite.Models;
    using OverrideThis.Core.Utilities;

    public class ContactManagerMapperProfile : Profile
    {
        public override string ProfileName
        {
            get
            {
                return "ContactManager";
            }
        }
        protected override void Configure()
        {
            this.CreateMap<Person, PersonViewModel>()
                .ForMember(m => m.CountryDescription, a => a.MapFrom(p => EnumHelper.GetDescription(p.Country)))
                .ForMember(m => m.TypeOfContact, a => a.MapFrom(p => EnumHelper.ToKeyValuePair(typeof(ContactType))));
            this.CreateMap<Person, PersonEditViewModel>()
                .ForMember(m => m.CountryDescription, a => a.MapFrom(p => EnumHelper.GetDescription(p.Country)))
                .ForMember(m => m.TypeOfContact, a => a.MapFrom(p => EnumHelper.ToKeyValuePair(typeof(ContactType))))
                .ForMember(m => m.Country, a => a.MapFrom(p => EnumHelper.ToKeyValuePair(typeof(Country))));
            this.CreateMap<PersonEditViewModel, PersonEditViewModel>()
                .ForMember(m => m.Country, a => a.MapFrom(p => EnumHelper.ToKeyValuePair(typeof(Country))))
                .ForMember(m => m.TypeOfContact, a => a.MapFrom(p => EnumHelper.ToKeyValuePair(typeof(ContactType))));
            this.CreateMap<IEnumerable<Person>, PersonListViewModel>()
                .ForMember(m => m.SelectedPersonId, a => a.Ignore())
                .ForMember(m => m.Persons, a => a.MapFrom(p => p))
                .ForMember(m => m.TypeOfContact, a => a.MapFrom(p => EnumHelper.ToKeyValuePair(typeof(ContactType))));
            this.CreateMap<Contact, ContactViewModel>();
            this.CreateMap<Email, EmailViewModel>();
        }
    }
}